package tongwentongshu.com.app.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import tongwentongshu.com.app.R;
import tongwentongshu.com.app.bean.TextEvent;
import tongwentongshu.com.app.db.Cache;
import tongwentongshu.com.app.utils.ToastUtil;

/**
 * Created by XiongBin on 2017/7/28.
 */

public class PersonalInformationActivity extends BaseActivity {
    @BindView(R.id.tv_user_nickname)
    TextView nickname;
    @BindView(R.id.tv_user_sex)
    TextView sex;
    @BindView(R.id.tv_user_place)
    TextView place;
    @BindView(R.id.tv_info)
    TextView info;


    @Override
    protected int getLayoutResourceId() {
        return R.layout.activity_personal_information;
    }

    @Override
    protected int getTitleId() {
        return R.string.personal_information;
    }

    @Override
    protected void initView() {
        nickname.setText(Cache.getUser().getData().getNickname());
        sex.setText(Cache.getUser().getData().getSex().equals("2") ? "女" : "男");
        place.setText(Cache.getUser().getData().getProvince());
    }

    @Override
    protected void initData() {

    }

    public void onEventMainThread(TextEvent result) {
        if (!TextUtils.isEmpty(result.getInfo())) {
            ToastUtil.show(mContext, "个人介绍修改成功！");
            info.setText(result.getInfo());
        } else if (!TextUtils.isEmpty(result.getNickname())) {
            ToastUtil.show(mContext, "昵称修改成功！");
            nickname.setText(result.getNickname());
        }
    }

    @OnClick({R.id.rel_nickname, R.id.rel_sex, R.id.rel_place, R.id.iv_edit})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rel_nickname:
                Bundle b = new Bundle();
                b.putString("type", "nickname");
                b.putInt("textId", R.string.nickname);
                b.putInt("textHint", R.string.nickname_hint);
                startActivity(PublicTextActivity.class, b);
                break;
            case R.id.rel_sex:
            case R.id.rel_place:
                if (Cache.getUser().getData().getUser_status().equals("2")) {
                    startActivity(RealNameAuthenticationActivity.class);
                }
                break;
            case R.id.iv_edit:
                Bundle infob = new Bundle();
                infob.putString("type", "note");
                infob.putInt("textId", R.string.per_info);
                infob.putInt("textHint", R.string.per_info_hint);
                startActivity(PublicTextActivity.class, infob);
                break;
        }
    }
}
